import axios from '@/libs/api.request'
import {
  format
} from 'path';
import {
  getToken,
  URL
} from "@/libs/util";

// 以防命名冲突
const HOST = URL

/**
 * @param {*} token
 * @param {*} formData  数据
 * @param {*} objKey    对象的KEY
 * @returns
 */

// 单位分类
function userClassData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  }
  data[keyOne] = {
    weightList: formData.weightList,
    delList: formData.delList, // 删除考核事项list
    itemList: formData.itemList, // 考核事项
    id: formData.id, // 行id
    classId: formData.classId, // 分类id
    datetime: formData.datetime,
    classname: formData.classname, // 分类名
    indexWeigh: formData.indexWeigh, // 指标权重
    factWeigh: formData.factWeigh, // 实事重点权重
    puExamWeigh: formData.puExamWeigh, // 公众评议权重
    xwdcWeigh: formData.xwdcWeigh, // 县委督查权重
    xzfdcWeigh: formData.xzfdcWeigh, // 县政府的督查权重
    ldbzjsWeigh: formData.ldbzjsWeigh, // 领导班子建设权重
    jgdjWeigh: formData.jgdjWeigh, // 机关党建权重
    pageSize: formData.pageSize, // 显示页数
    pageNumber: formData.pageNumber // 页码

  }
  return data
}

// 账号管理
function userData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  }

  data[keyOne] = {
    listId: formData.listId, // 批量修改单位分类
    id: formData.id,
    roleid: formData.roleid, // 搜索用户角色下拉id
    userName: formData.userName, // 用户名
    nickName: formData.nickName, // 用户名
    userPosition: formData.userPosition, // 用户职务
    departcode: formData.departcode, // 弹窗部门
    userDepartment: formData.userDepartment, // 搜索部门code
    userPermissions: formData.userPermissions, // 用户权限
    userPhone: formData.userPhone, // 用户手机
    department: formData.department, // 部门
    userPassword: formData.userPassword, // 用户密码
    departAddr: formData.departAddr, // 部门简称
    departType: formData.departType, // 部门类型
    departClas: formData.departClas, // 部门分类
    departOldName: formData.departOldName, // 部门旧名称
    departOldAddr: formData.departOldAddr, // 部门旧简称
    remark: formData.remark, // 备注
    isManger: formData.isManger, // 是否为管理员
    isLeader: formData.isLeader, // 是否为县领导

    checkAllGroup: formData.checkAllGroup, // 权限值
    btnRights: formData.btnRights, // 增删改查权限值

    checkAllindexGroup: formData.checkAllindexGroup, // 所选中县指标集合
    checkCityGroup: formData.checkCityGroup, // 所选中市指标集合
    checkUnitGroup: formData.checkUnitGroup, // 所选中单位指标集合

    pageSize: formData.pageSize, // 显示页数
    pageNumber: formData.pageNumber // 页码
  }
  return data
}

// 登录次数详情数据
function loginDetailData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  }

  data[keyOne] = {
    id: formData.id,
    pageSize: formData.pageSize, // 显示页数
    pageNumber: formData.pageNumber // 页码
  }
  return data
}

// 角色管理数据
function roletMangeData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };
  data[keyOne] = {
    id: formData.id, // id
    userType: formData.userType,
    optionType: formData.optionType,
    role: formData.role, // 角色
    checkAllGroup: formData.checkAllGroup, // 权限值
    btnRights: formData.btnRights, // 增删改查权限值
    checkAllindexGroup: formData.checkAllindexGroup, // 所选中指标集合
    checkCityGroup: formData.checkCityGroup, // 所选中市指标集合
    checkUnitGroup: formData.checkUnitGroup, // 所选中单位指标集合
    isManger: formData.isManger, // 是否为管理员
    pageSize: formData.pageSize, // 显示页数
    pageNumber: formData.pageNumber // 页码
  }
  return data
}
// 设置时间数据
function setTimeData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  }

  data[keyOne] = {

    indexClass: formData.indexClass, // 标题code
    startTime: formData.startTime, // 开始时间
    endTime: formData.endTime, // 结束时间
    isThisMonth: formData.isThisMonth // 是否当月

  }
  return data
}

// 请求自定义时间数据
function queryTimeData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };
  data[keyOne] = {
    indexClass: formData.indexClass // 标题code
  }
  return data
}

// 用户管理 编辑用户角色请求
function editorRoleData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };
  data[keyOne] = {
    roleid: formData.roleid, // 标题code
    checkAllGroup: formData.checkAllGroup, // 菜单权限值
    btnRights: formData.btnRights, // 增删改查权限值
    checkAllindexGroup: formData.checkAllindexGroup, // 所选中指标集合
    checkCityGroup: formData.checkCityGroup, // 所选中市指标集合
    checkUnitGroup: formData.checkUnitGroup // 所选中单位指标集合
  }
  return data
}

// 验证用户名是否重复
function verifyUserNameData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };
  data[keyOne] = {
    userName: formData.userName
  }
  return data
}

// 用户管理 导入用户信息
function importUserData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };
  data[keyOne] = {
    listUser: formData.list[0].listUser, // 表格数据
    checkCode: formData.checkCode // 校验code
  }
  return data
}
// 批量修改用户权限
function bulkChangeData(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };
  data[keyOne] = {
    ids: formData.ids, // 用户id
    checkAllGroup: formData.checkAllGroup, // 菜单权限值
    btnRights: formData.btnRights, // 增删改查权限值
    checkAllindexGroup: formData.checkAllindexGroup, // 所选中指标集合
    checkCityGroup: formData.checkCityGroup, // 所选中市指标集合
    checkUnitGroup: formData.checkUnitGroup // 所选中单位指标集合
  }
  return data
}

// 批量修改用户角色
function bathModifyRole(formData, keyOne) {
  let data = {}
  data['tokenEntity'] = {
    value: getToken()
  };
  data[keyOne] = {
    ids: formData.ids, // 用户id
    roleid: formData.roleid /// 用户角色
  }
  return data
}

// 单位分类
export const userClassificationAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = userClassData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

// 用户管理 and  单位管理 共用
export const userAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = userData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

// 用户管理里的登录详情
export const loginDetailAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = loginDetailData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

/**
 *角色管理
 */
export const roleMangeAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = roletMangeData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

// 自定义填写时间
export const setTimeAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = setTimeData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

// 自定义填写时间QUERY
export const queryTimeAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = queryTimeData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

/**
 *用户管理 编辑用户角色请求
 */
export const editorRoleAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = editorRoleData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

/**
 *用户管理 用户名重复验证
 */
export const verifyUserNameAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = verifyUserNameData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

/**
 *用户管理 导入用户信息
 */
export const importUserInfotAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = importUserData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

/**
 *批量修改用户权限
 */
export const bulkChangeAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = bulkChangeData(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}

/**
 *批量修改用户权限
 */
export const bathModifyRoleAjax = ({
  formData,
  url,
  keyOne
}) => {
  let data = ''
  data = bathModifyRole(formData, keyOne)
  return axios.request({
    url: HOST + url,
    data,
    method: 'post'
  })
}
